﻿using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Abp.Application.Services.Dto;
using Abp.AspNetCore.Mvc.Authorization;
using ABP.TPLMS.Authorization;
using ABP.TPLMS.Controllers;
using ABP.TPLMS.Books;
using ABP.TPLMS.Web.Models.Books;
using ABP.TPLMS.Books.Dto;

namespace ABP.TPLMS.Web.Controllers
{
    //[AbpMvcAuthorize(PermissionNames.Pages_Book)]
    public class BookController : TPLMSControllerBase
    {
        private readonly IBookAppService _userAppService;

        public BookController(IBookAppService userAppService)
        {
            _userAppService = userAppService;
        }

        public async Task<ActionResult> Index()
        {
            var users = (await _userAppService.GetAll(new PagedBookResultRequestDto {MaxResultCount = int.MaxValue})).Items; // Paging not implemented yet
            var model = new BookListViewModel
            {
                Books = users,
               
            };
            return View(model);
        }

        public async Task<ActionResult> EditBookModal(Guid userId)
        {
            var book = await _userAppService.Get(new EntityDto<Guid>(userId));
            
            var model = new EditBookModalViewModel
            {
                Book = book,
            };
            return View("_EditBookModal", model);
        }
    }
}
